const tokenName = 'xiaolvknowlaw-app-token';
const websocketName = 'xiaolvknowlaw-websocket-token';

const handleToken = {
	getTokenSync() {
		return uni.getStorageSync(tokenName)
	},
	setTokeSync(token) {
		return uni.setStorageSync(tokenName, token)
	},
	removeTokenSync() {
		return uni.removeStorageSync(tokenName)
	},
	getToken() {
		return new Promise((resolve, reject) => {
			uni.getStorage({
				key: tokenName,
				success(res) {
					resolve(res);
				},
				fail(err) {
					reject(err);
				}
			})
		})
	},
	setToken(token) {
		return new Promise((resolve, reject) => {
			uni.setStorage({
				key: tokenName,
				data: token,
				success(res) {
					resolve(res)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	removeToken() {
		return new Promise((resolve, reject) => {
			uni.removeStorage({
				key: tokenName,
				success(res) {
					resolve(res)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getHXTokenSync() {
		return uni.getStorageSync(websocketName)
	},
	setHXTokeSync(token) {
		return uni.setStorageSync(websocketName, token)
	},
	removeHXTokenSync() {
		return uni.removeStorageSync(websocketName)
	},
}

module.exports = {
	methods: {
		...handleToken
	}
}
